export default class WireFrame extends zrender.Group {
    constructor(node) {
        super();
        this.node = node;
        this.init();
    }
    init() {
        this.beforeCreate();
        this.create();
    }
    beforeCreate() {
        this.rect = new zrender.Rect({
            style: {
                fill: '#f5f5f5',
                stroke: '#666',
                lineDash:[8, 4]
            }
        });
        this.add(this.rect);
        this.rect.animate('style',true)
            .when(1000,{lineDashOffset:Math.random()>0.5?12:-12})
            .start();
    }
    create() {
       var nodes=this.node.getNodeList();
       var box=this.getBoundingRect(nodes);
       this.setPosition(box.x-4,box.y-4);
       this.rect.attr({
           shape:{
               x:0,
               y:0,
               width:box.width+8,
               height:box.height+8,
               r:[3]
           }
       });
    }
    refresh(){
        this.create();
    }
    setPosition(x,y){
        this.attr({
            position:[x,y]
        });
    }
    getPosition(){
        return {
            x:this.position.slice()[0],
            y:this.position.slice()[1]
        }
    }
}